<template>
  <view class="cart-container">
    <view class="empty-cart" v-if="!cart.length">
      <image src="/static/cart_empty@2x.png" class="empty-img"></image>
          <text class="tip-text">空空如也~</text>
    </view>
    <view v-else>
    <my-address></my-address>
    <!-- 购物车列表标题 -->
    <view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <view class="cart-title-text">
        购物车
      </view>
    </view>
    <!-- 商品列表区域 -->
    <uni-swipe-action>
      <view v-for="(item ,i) in cart" :key="i">
        <uni-swipe-action-item :options="options" @click="swipeAction(item)">
          <my-goods :goods="item" :showRadio="true" :showNum="true" @radio-change="radioChange" @num-change="numChange"/>
        </uni-swipe-action-item>
      </view>
    </uni-swipe-action>
    <my-settle></my-settle>
  </view>
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    mixins: [badgeMix],
    computed: {
      ...mapState('m_cart', ['cart'])
    },
    data() {
      return {
        options: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }]
      };
    },
    onLoad() {
      console.log(this.cart)
    },
    methods: {
      ...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount','delCartGoods']),
      // 按钮发生变化
      radioChange(e) {
        // console.log(e)
        this.updateGoodsState(e)
      },
      // 商品数量发生变化
      numChange(e) {
        this.updateGoodsCount(e)
      },
      swipeAction(goods){
        this.delCartGoods(goods.goods_id)
      },
    }
  }
</script>

<style lang="scss">
  .cart-container{
    margin-bottom: 50px;
.empty-cart {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;

  .empty-img {
    width: 90px;
    height: 90px;
  }

  .tip-text {
    font-size: 12px;
    color: gray;
    margin-top: 15px;
  }
}
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    font-size: 14px;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;

    .cart-title-text {
      margin-left: 10px;
    }
  }

}
</style>
